﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Pvr_UnitySDKAPI;

namespace Assets.Scripts.TDu3DWork
{
    class TDuEventArgs
    {
        public string m_strEventID;
    }

    class TDuVRControllerEventArgs : TDuEventArgs
    {
        public enum VRCONTROLLCMD
        {
            LEFT_CONTROLLER_TRIGGER,
            LEFT_CONTROLLER_LEFT,  //手柄0的右侧建;
            LEFT_CONTROLLER_HOME,
            LEFT_CONTROLLER_APP,
            LEFT_CONTROLLER_X,  //手柄0
            LEFT_CONTROLLER_Y,  //手柄0
            LEFT_CONTROLLER_TOUCHPAD,

            RIGHT_CONTROLLER_RIGHT, //手柄1的右侧按键
            RIGHT_CONTROLLER_TRIGGER,
            RIGHT_CONTROLLER_HOME,
            RIGHT_CONTROLLER_APP,
            RIGHT_CONTROLLER_A,
            RIGHT_CONTROLLER_B,
            RIGHT_CONTROLLER_TOUCHPAD,

            LEFT_CONTROLLER_TOUCHPAD_UP,
            RIGHT_CONTROLLER_TOUCHPAD_UP,
            NONE,
        }

        private static Dictionary<Pvr_KeyCode,VRCONTROLLCMD> m_controllerDictionary = new Dictionary<Pvr_KeyCode, VRCONTROLLCMD>();
        public VRCONTROLLCMD m_emVRControllerCmd;

        public TDuVRControllerEventArgs()
        {
            m_strEventID = "VRController_Event";
            m_emVRControllerCmd = VRCONTROLLCMD.NONE;
        }
        public void getVRControllerCmd()
        {
            if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.HOME))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_HOME;
            else if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.APP))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_APP;
            else if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TRIGGER))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_TRIGGER;
            else if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.Left))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_LEFT;
            else if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.X))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_X;
            else if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.Y))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_Y;
            else if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TOUCHPAD))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_TOUCHPAD;
            //右手
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.HOME))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_HOME;
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.APP))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_APP;
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER) || Input.GetKeyDown(KeyCode.T))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_TRIGGER;
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.Left))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_RIGHT;
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.A))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_A;
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.B))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_B;
            else if (Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TOUCHPAD))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_TOUCHPAD;

            else if (Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.TOUCHPAD))
                m_emVRControllerCmd = VRCONTROLLCMD.LEFT_CONTROLLER_TOUCHPAD_UP;
            else if (Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.TOUCHPAD))
                m_emVRControllerCmd = VRCONTROLLCMD.RIGHT_CONTROLLER_TOUCHPAD_UP;
        }
    }

    class TDuShellEventArgs : TDuEventArgs
    {
        public enum SHELLCMD
        {
            BACKMAINMENU,
            FORWARDMODULE,
            SHOWSCORES,
            NONE,
        }

        public SHELLCMD m_emShellCmd;
        public TDuShellEventArgs()
        {
            m_strEventID = "ShellCmd_Event";
            m_emShellCmd = SHELLCMD.NONE;
        }
    }

    class TDuPostEventArgs : TDuEventArgs
    {
        public enum POSTACTION
        {
            RAYCAST,
            HIT,
            VIDEOWND,
            DIALOGURE,
            QUESTIONWND,
            SCROLLSTEP,
            TIPPICTURE,
            JUDGE,
            GOODS,
            NONE,
        }

        private static Dictionary<string, POSTACTION> m_postActionDictionary = new Dictionary<string, POSTACTION>();
        public POSTACTION m_emPostAction;
        public TDuResource.VariableNode m_varNode;

        public TDuPostEventArgs()
        {
            m_strEventID = "PostAction_Event";
            m_emPostAction = POSTACTION.NONE;            
        }

        public static void registerPostActionDictionary( )
        {
            m_postActionDictionary.Clear();
            m_postActionDictionary.Add("VideoWnd", POSTACTION.VIDEOWND);
            m_postActionDictionary.Add("Hit", POSTACTION.HIT);
            m_postActionDictionary.Add("Dialog", POSTACTION.DIALOGURE);
            m_postActionDictionary.Add("QuestionWnd", POSTACTION.QUESTIONWND);
            m_postActionDictionary.Add("TipPicture", POSTACTION.TIPPICTURE);
            m_postActionDictionary.Add("JudgeExm", POSTACTION.JUDGE);
            m_postActionDictionary.Add("GoodsReady", POSTACTION.GOODS);
            m_postActionDictionary.Add("Step", POSTACTION.SCROLLSTEP);
            m_postActionDictionary.Add("MouseRayCast", POSTACTION.RAYCAST);
        }
        
        public void getPostActionType( string strAction )
        {
            if (!m_postActionDictionary.ContainsKey(strAction))
                m_emPostAction = POSTACTION.NONE;

            Debug.Log("straction:       " + strAction);
            m_postActionDictionary.TryGetValue(strAction, out m_emPostAction);
        }
    }
}
